const http = require("http");
const fs = require("fs");

http
  .createServer((req, res) => {
    // console.log(req.url);
    const { url } = req;

    switch (url) {
      case "/":
        fs.readFile("./index.html", "utf-8", (err, data) => {
          if (err) throw err;
          res.write(data);
          res.end();
        });
        break;
      case "/detail":
        fs.readFile("./detail.html", "utf-8", (err, data) => {
          if (err) throw err;
          res.write(data);
          res.end();
        });
        break;
      case "/style.css":
        fs.readFile("./style.css", "utf-8", (err, data) => {
          if (err) throw err;
          res.write(data);
          res.end();
        });
        break;
      default:
        res.write("404 not found...");
        res.end();
    }
  })
  .listen(3000);
